# One Away: There are three types of edits that can be performed on strings: insert a character,
# remove a character, or replace a character. Given two strings, write a function to check if they are
# one edit (or zero edits) away.
# EXAMPLE
# pale, ple -) true
# pales, pale -) true
# pale, bale -) true
# pale, bae -) false

def checkOneEdit(s1,s2):
    if len(s1) == len(s2):
        return _checkReplace(s1,s2)
    if len(s1) + 1 == len(s2):
        return _checkInsert(s1,s2)
    if len(s1) - 1 == len(s2):
        return _checkInsert(s2,s1)
    return False

def _checkReplace(s1,s2):
    diff = False
    for x,y in zip(s1,s2):
        if x != y:
            if diff:
                return False
        diff = True
    return True

def _checkInsert(s1,s2):
    idx1 = 0 
    idx2 = 0
    while(idx1 < len(s1) and idx2 < len(s2)):
        if s1[idx1] != s2[idx2]:
            if idx1 != idx2:
                return False
            idx2+=1
        else:
            idx1+=1
            idx2+=1
    return True

print(checkOneEdit('pale', 'bae'))